﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WinFileTransfer
{
    public partial class FrmRename : Form
    {
        public FrmRename(string path)
        {
            InitializeComponent();
            _ThisFile = new FileInfo(path);
            tboxDirectory.Text = _ThisFile.DirectoryName;
            tboxNewName.Text = _ThisFile.Name;
        }

        public FrmRename(FileInfo fileInfo)
        {
            InitializeComponent();
            _ThisFile = fileInfo;
            tboxDirectory.Text = _ThisFile.DirectoryName;
            tboxNewName.Text = _ThisFile.Name;
        }

        private FileInfo _ThisFile = null;
        
        private void btnOk_Click(object sender, EventArgs e)
        {
            string path = tboxDirectory.Text + "\\" + tboxNewName.Text;
            if (File.Exists(path))
            {
                DialogResult result = MessageBox.Show("该目录下已存在同名文件，是否替换该文件？", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.No)
                {
                    return;
                }
            }
            _ThisFile.MoveTo(path);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
